package com.ttn.student.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ttn.common.core.entity.Result;
import com.ttn.common.core.entity.studentrecord.EvaluationRecord;
import com.ttn.student.service.EvaluationRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * (evaluation_record)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/evaluation-record")
@Slf4j
public class EvaluationRecordController {
    /**
     * 服务对象
     */
    @Resource
    private EvaluationRecordService evaluationRecordService;

    /**
     * 保存测评记录
     *
     * @param request
     * @param evaluationRecord
     * @return
     */
    @PostMapping("/save/evaluation-record")
    public Result saveEvaluationRecord(HttpServletRequest request, @RequestBody EvaluationRecord evaluationRecord) {
        log.info("EvaluationRecordController saveEvaluationRecord ,参数:{}", evaluationRecord);
        evaluationRecordService.save(evaluationRecord);
        return Result.success();
    }

    @PostMapping("/query/evaluation-record/{studentId}")
    public Result queryEvaluationRecordByStudentId(HttpServletRequest request, @PathVariable int studentId) {
        log.info("EvaluationRecordController queryEvaluationRecordByStudentId ,参数:{}", studentId);
        LambdaQueryWrapper<EvaluationRecord> evaluationRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
        evaluationRecordLambdaQueryWrapper.eq(EvaluationRecord::getStudentId, studentId);
        return Result.success(evaluationRecordService.getOne(evaluationRecordLambdaQueryWrapper));
    }


}
